package 代码coding题OR模拟题;
import java.util.HashSet;
import java.util.TreeMap;
import java.util.Comparator;
import java.util.HashMap;
/**
 * 
 * 从这里面 也可以 看出来 一些东西 在 里面
 * 	HashSet<String> set = new HashSet<>();
		String s1 = new String("aa");
		String s2 = "aa";
		System.out.println(s1 == s2);
		set.add(s2);
		set.add(s1);
		System.out.println(set.size());
		String str = "Aaa.";
		System.out.println(str.toLowerCase());
 */

//  倒在 了 这样的 测试 用例 上面  "a,b,b,b, c" 这他妈 能叫 英语 段落 傻逼 搁着
public class leetcode819最常见的单词 {
	
	public static void main(String []args) {
		String paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.";
//		String paragraph = "Bob hit a ball. Hit a scale.";
		String [] banned = {"hit"};
		String str = "abcd";
		System.out.println(str.substring(3));
		System.out.println(solution(paragraph,banned));
		System.out.println(judge('.'));
	
	}
	
	public static String solution(String s,String [] banned) {
//		TreeMap<String,Integer> map = new TreeMap<>();
		HashMap<String,Integer> map = new HashMap<>();
		String [] splitArr = s.split(" ");
		HashSet<String> ban = new HashSet<>();
		for(String str : banned) {
			ban.add(str);
		}
		for(String str : splitArr) {
			String  temp = str;
			if(!judge(str.charAt(str.length()-1)))
				temp = str.substring(0,str.length() - 1);
			temp = temp.toLowerCase();
			if(!ban.contains(temp)) {
				if(map.containsKey(temp)) {
					map.put(temp, map.get(temp) + 1);
				}
				else
					map.put(temp, 1);
			}
		}
		String ans ="";
		int max  = Integer.MIN_VALUE;
		for(String str : map.keySet()) {
//			int value = map.get(str);
			if(max < map.get(str)) {
				ans = str;
				max = map.get(str);
			}
		}
		return ans;
	}
	public static boolean judge(char c) {
//		if( ('a'<= c && c <= 'z') || ( 'A'<=c && c<= 'Z')) {
//			return true;
//		}
//		return false;
//		return ('a'<= c && c <= 'z') || ( 'A'<=c && c<= 'Z') ? true : false;
	//  省来 省去  还是下面 最直接
		return ('a'<= c && c <= 'z') || ( 'A'<=c && c<= 'Z');
	}

}
